﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace CSSAdriverapp
{
    /// <summary>
    /// Interaction logic for DriverInfo.xaml
    /// </summary>
    public partial class DriverInfo : Window
    {
        public DriverInfo()
        {
            InitializeComponent();
            populateGrid();
        }

        public void populateGrid()
        {
            DataClassesDataContext db = new DataClassesDataContext();
            IQueryable<Driver> drivers = from c in db.Drivers select c;
            drivers.ToList();
            dataGrid1.ItemsSource = drivers;
        }

        public List<Driver> drivers
        {
            get;
            set;
        }

        public List<COMSERV_ACTIVITY> activities
        {
            get;
            set;
        }

        public List<driver_availability> availabilities
        {
            get;
            set;
        }

        private void dataGrid1_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            if (dataGrid1.SelectedItem != null)
            {
                label1.Content = ((Driver)(dataGrid1.SelectedItem)).EMail;
                label2.Content = ((Driver)(dataGrid1.SelectedItem)).PhoneNumber;

                DataClassesDataContext db = new DataClassesDataContext();

                //---grid 2 bind
                IQueryable<Event> allevents = from c in db.Events where c.DriverID == ((Driver)(dataGrid1.SelectedItem)).ID select c;                    
                IQueryable<COMSERV_ACTIVITY> activs = (from c in db.COMSERV_ACTIVITies join o in allevents on c.activityid equals o.ServiceID select c).Distinct();
                activities = activs.ToList();
                dataGrid2.ItemsSource = activities;

                //---grid 3 bind
                IQueryable<driver_availability> availabilities = from d in db.driver_availabilities where d.driverID == ((Driver)(dataGrid1.SelectedItem)).ID select d;
                dataGrid3.ItemsSource = availabilities;
            }
        }

        
    }

}
